﻿/*--------------------------------------------------------------
 * Author : Shine K Velayudhan 
 ---------------------------------------------------------------*/
using System.Diagnostics;

namespace IQN.Logging
{
    public static class TraceLogExtensions
    {
        private static void log(ILogger logger, MessageLevel severity, string message, object param1, object param2)
        {
            if (null != logger)
            {
                logger.Log(severity, message, param1, param2);
            }
        }

        public static void Critical(this ILogger logger, string message)
        {
            log(logger, MessageLevel.Critical, message, string.Empty, string.Empty);
        }

        public static void Critical(this ILogger logger, string message, object param)
        {
            log(logger, MessageLevel.Critical, message, param, string.Empty);
        }

        public static void Critical(this ILogger logger, string message, object param1, object param2)
        {
            log(logger, MessageLevel.Critical, message, param1, param2);
        }

        [Conditional("DEBUG")]
        public static void EnteringBlock(this ILogger logger, string blockName)
        {
            log(logger, MessageLevel.Verbose, "Entering block: {0}", blockName, string.Empty);
        }

        [Conditional("DEBUG")]
        public static void EnteringMethod(this ILogger logger, string methodName)
        {
            log(logger, MessageLevel.Verbose, "Entering method: {0}", methodName, string.Empty);
        }

        public static void Info(this ILogger logger, string message)
        {
            log(logger, MessageLevel.Info, message, string.Empty, string.Empty);
        }

        public static void Info(this ILogger logger, string message, object param)
        {
            log(logger, MessageLevel.Info, message, param, string.Empty);
        }

        public static void Info(this ILogger logger, string message, object param1, object param2)
        {
            log(logger, MessageLevel.Info, message, param1, param2);
        }

        [Conditional("DEBUG")]
        public static void LeavingBlock(this ILogger logger, string blockName)
        {
            log(logger, MessageLevel.Verbose, "Leaving block: {0}", blockName, string.Empty);
        }

        [Conditional("DEBUG")]
        public static void LeavingMethod(this ILogger logger, string methodName)
        {
            log(logger, MessageLevel.Verbose, "Leaving method: {0}", methodName, string.Empty);
        }

        [Conditional("DEBUG")]
        public static void Verbose(this ILogger logger, string message)
        {
            log(logger, MessageLevel.Verbose, message, string.Empty, string.Empty);
        }

        [Conditional("DEBUG")]
        public static void Verbose(this ILogger logger, string message, object param)
        {
            log(logger, MessageLevel.Verbose, message, param, string.Empty);
        }

        [Conditional("DEBUG")]
        public static void Verbose(this ILogger logger, string message, object param1, object param2)
        {
            log(logger, MessageLevel.Verbose, message, param1, param2);
        }

        public static void Warn(this ILogger logger, string message)
        {
            log(logger, MessageLevel.Warning, message, string.Empty, string.Empty);
        }

        public static void Warn(this ILogger logger, string message, object param)
        {
            log(logger, MessageLevel.Warning, message, param, string.Empty);
        }

        public static void Warn(this ILogger logger, string message, object param1, object param2)
        {
            log(logger, MessageLevel.Warning, message, param1, param2);
        }
    }
}
